package com.formula.propertyshop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.formula.propertyshop.R;
import com.formula.propertyshop.model.Property;
import com.formula.propertyshop.utils.DeviceInfo;
import com.formula.propertyshop.utils.WFUtils;
import com.squareup.picasso.Picasso;

public class PropertyImageGalleryAdapter extends BaseAdapter{
	
	private Context context;
	private String listImgGalleryUrl[];
	public PropertyImageGalleryAdapter(Context c, Property p) {
		context = c;
		listImgGalleryUrl = WFUtils.removeNull(p.getImgGalleryUrl());
		
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listImgGalleryUrl.length;
	}

	@Override
	public Object getItem(int arg0) {
		return listImgGalleryUrl[arg0];
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		  ImageView imageView;
	        if (convertView == null) {  // if it's not recycled, initialize some attributes
	            imageView = new ImageView(context);
	            imageView.setLayoutParams(new Gallery.LayoutParams(DeviceInfo.ScreenWidth-DeviceInfo.convertDPIToPixel(100), DeviceInfo.convertDPIToPixel(200)));
	            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
	            String url =getItem(arg0).toString();
	            Picasso.with(context).load(url).fit().centerInside().error(R.drawable.noimage).placeholder(R.drawable.noimage).into(imageView);
	            imageView.setPadding(8, 8, 8, 8);
	        } else {
	            imageView = (ImageView) convertView;
	        }

		
		return imageView;
	}

}
